import { createRouter, createWebHistory } from 'vue-router'
import _ from 'lodash'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      component: () => import('../pages/Home.vue')
    },
    {
      path: '/subapp/sub-vue2/:pathMatch(.*)*',
      // 将qiankun的渲染容器container，单独拆分一个组件页面，解决路由警告的问题
      component: () => import('../qiankun/SubAppContainer.vue')
    },
    {
      path: '/sub-vue3/:pathMatch(.*)*',
      component: () => import('../qiankun/SubAppContainer.vue')
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (_.isEmpty(history.state.current)) {
    _.assign(history.state, { current: from.fullPath });
  }
  next();
});

export default router
